/*
    File:       RTSPProtocol.h

    Contains:   A grouping of static utilities that abstract keyword strings
                in the RTSP protocol. This should be maintained as new versions
                of the RTSP protoocl appear & as the server evolves to take
                advantage of new RTSP features.

    

*/


#ifndef __RTSPPROTOCOL_H__
#define __RTSPPROTOCOL_H__

#ifdef __Win32__
#pragma warning(disable:4786)
#endif


#include "StrPtrLen.h"

/*
  *some defines about RTSP method type, header type, status code
  */


#ifdef __cplusplus
extern "C" {
#endif

#include "OSHeaders.h"

//the type of RTSP method
enum
{
    RTSPDescribeMethod      = 0, 
    RTSPSetupMethod,
    RTSPTeardownMethod,
    RTSPPlayMethod,
    RTSPPauseMethod,
    RTSPOptionsMethod		= 5,
    RTSPAnnounceMethod,
    RTSPGetParameterMethod,
    RTSPSetParameterMethod,
    RTSPRedirectMethod,
    RTSPRecordMethod		= 10,
    RTSPClientResponse
};

enum
{
	RTSPNumVIPMethods       = 3,
	RTSPNumMethods			= 12,
	
    RTSPIllegalMethod		= 12
};

typedef UInt32 RTSPMethod;

enum
{
	RTPNetworkModeDefault       = 0, // not declared
		RTPNetworkModeMulticast     = 1,
		RTPNetworkModeUnicast       = 2
};
typedef UInt32 RTPNetworkMode;


/**********************************/
//
// The transport mode in a SETUP request
enum
{
    RTPTransportModePlay        = 0,
		RTPTransportModeRecord      = 1
};
typedef UInt32 RTPTransportMode;

/**********************************/
//
// What type of RTP transport is being used for the RTP stream?
enum
{
    RTPTransportTypeUDP         = 1,
    RTPTransportTypeTCP         = 2,
    RDTTransportTypeTCP         =3,
    RDTTransportTypeUDP         =4
};

typedef UInt32 RTPTransportType;



//the type of RTSP request parameter
enum
{
    //These are the common request headers (optimized)
    RTSPAcceptHeader            = 0,
    RTSPCSeqHeader              = 1,
    RTSPUserAgentHeader         = 2,
    RTSPTransportHeader         = 3,
    RTSPSessionHeader           = 4,
    RTSPRangeHeader             = 5,
    RTSPNumVIPHeaders           = 6,
    
    //Other request headers
    RTSPAcceptEncodingHeader    = 6,
    RTSPAcceptLanguageHeader    = 7,
    RTSPAuthorizationHeader     = 8,        
    RTSPBandwidthHeader         = 9,
    RTSPBlockSizeHeader         = 10,
    RTSPCacheControlHeader      = 11,
    RTSPConferenceHeader        = 12,       
    RTSPConnectionHeader        = 13,
    RTSPContentBaseHeader       = 14,
    RTSPContentEncodingHeader   = 15,
    RTSPContentLanguageHeader   = 16,
    RTSPContentLengthHeader     = 17,
    RTSPContentLocationHeader   = 18,
    RTSPContentTypeHeader       = 19,
    RTSPDateHeader              = 20,
    RTSPExpiresHeader           = 21,
    RTSPFromHeader              = 22,
    RTSPHostHeader              = 23,
    RTSPIfMatchHeader           = 24,
    RTSPIfModifiedSinceHeader   = 25,
    RTSPLastModifiedHeader      = 26,
    RTSPLocationHeader          = 27,
    RTSPProxyAuthenticateHeader = 28,
    RTSPProxyRequireHeader      = 29,
    RTSPRefererHeader           = 30,
    RTSPRetryAfterHeader        = 31,
    RTSPRequireHeader           = 32,
    RTSPRTPInfoHeader           = 33,
    RTSPScaleHeader             = 34,
    RTSPSpeedHeader             = 35,
    RTSPTimestampHeader         = 36,
    RTSPVaryHeader              = 37,
    RTSPViaHeader               = 38,
    RTSPNumRequestHeaders       = 39,
    
    //Additional response headers
    RTSPAllowHeader             = 39,
    RTSPPublicHeader            = 40,
    RTSPServerHeader            = 41,
    RTSPUnsupportedHeader       = 42,
    RTSPWWWAuthenticateHeader   = 43,
    RTSPSameAsLastHeader        = 44,
    
    //Newly added headers
    RTSPExtensionHeaders        = 45,
    
    RTSPXRetransmitHeader       = 45,
    RTSPXAcceptRetransmitHeader = 46,
    RTSPXRTPMetaInfoHeader      = 47,
    RTSPXTransportOptionsHeader = 48,
    RTSPXPacketRangeHeader      = 49,
    RTSPXPreBufferHeader        = 50,
    RTSPXDynamicRateHeader      = 51,
    RTSPXAcceptDynamicRateHeader= 52,
    RTSPNumHeaders				= 53,
    RTSPIllegalHeader 			= 53
    
};
typedef UInt32 RTSPHeader;


//the return code of RTSP request
enum
{
    RTSPContinue                        = 0,        //100
    RTSPSuccessOK                       = 1,        //200
    RTSPSuccessCreated                  = 2,        //201
    RTSPSuccessAccepted                 = 3,        //202
    RTSPSuccessNoContent                = 4,        //203
    RTSPSuccessPartialContent           = 5,        //204
    RTSPSuccessLowOnStorage             = 6,        //250
    RTSPMultipleChoices                 = 7,        //300
    RTSPRedirectPermMoved               = 8,        //301
    RTSPRedirectTempMoved               = 9,        //302
    RTSPRedirectSeeOther                = 10,       //303
    RTSPRedirectNotModified             = 11,       //304
    RTSPUseProxy                        = 12,       //305
    RTSPClientBadRequest                = 13,       //400
    RTSPClientUnAuthorized              = 14,       //401
    RTSPPaymentRequired                 = 15,       //402
    RTSPClientForbidden                 = 16,       //403
    RTSPClientNotFound                  = 17,       //404
    RTSPClientMethodNotAllowed          = 18,       //405
    RTSPNotAcceptable                   = 19,       //406
    RTSPProxyAuthenticationRequired     = 20,       //407
    RTSPRequestTimeout                  = 21,       //408
    RTSPClientConflict                  = 22,       //409
    RTSPGone                            = 23,       //410
    RTSPLengthRequired                  = 24,       //411
    RTSPPreconditionFailed              = 25,       //412
    RTSPRequestEntityTooLarge           = 26,       //413
    RTSPRequestURITooLarge              = 27,       //414
    RTSPUnsupportedMediaType            = 28,       //415
    RTSPClientParameterNotUnderstood    = 29,       //451
    RTSPClientConferenceNotFound        = 30,       //452
    RTSPClientNotEnoughBandwidth        = 31,       //453
    RTSPClientSessionNotFound           = 32,       //454
    RTSPClientMethodNotValidInState     = 33,       //455
    RTSPClientHeaderFieldNotValid       = 34,       //456
    RTSPClientInvalidRange              = 35,       //457
    RTSPClientReadOnlyParameter         = 36,       //458
    RTSPClientAggregateOptionNotAllowed = 37,       //459
    RTSPClientAggregateOptionAllowed    = 38,       //460
    RTSPClientUnsupportedTransport      = 39,       //461
    RTSPClientDestinationUnreachable    = 40,       //462
    RTSPServerInternal                  = 41,       //500
    RTSPServerNotImplemented            = 42,       //501
    RTSPServerBadGateway                = 43,       //502
    RTSPServerUnavailable               = 44,       //503
    RTSPServerGatewayTimeout            = 45,       //505
    RTSPRTSPVersionNotSupported         = 46,       //504
    RTSPServerOptionNotSupported        = 47,       //551
    RTSPNumStatusCodes                  = 48
    
};
typedef UInt32 RTSPStatusCode;

#ifdef __cplusplus
}
#endif


// add by bound
typedef enum {
	NORMAL_RTSP,
	RM_RTSP
}RTSP_TYPE;
// end add

/*
  *the static class for RTSP interactivity, including some static processing functions for RTSP protocol
  */

class RTSPProtocol
{
    public:

        //METHODS
        
           
        //The lookup function. Very simple
        static UInt32   GetMethod(const StrPtrLen &inMethodStr);
        //return the string of some method
        static StrPtrLen&   GetMethodString(RTSPMethod inMethod)
            { return sMethods[inMethod]; }


        
        //HEADERS

        //  Header enumerated type definitions in RTSPProtocol.h
        
        //The lookup function. Very simple
        static UInt32 GetRequestHeader(const StrPtrLen& inHeaderStr);        
        //The lookup function. Very simple.
        static StrPtrLen& GetHeaderString(UInt32 inHeader)
            { return sHeaders[inHeader]; }
        
        
        //STATUS CODES

        //returns name of this error
        static StrPtrLen&       GetStatusCodeString(RTSPStatusCode inStat)
            { return sStatusCodeStrings[inStat]; }
        //returns error number for this error
        static Int32           GetStatusCode(RTSPStatusCode inStat)
            { return sStatusCodes[inStat]; }
        //returns error number as a string
        static StrPtrLen&       GetStatusCodeAsString(RTSPStatusCode inStat)
            { return sStatusCodeAsStrings[inStat]; }
        



        // VERSIONS
        enum RTSPVersion
        {
            k10Version = 0,
            kIllegalVersion = 1
        };


        
        // NAMES OF THINGS
        static StrPtrLen&       GetRetransmitProtocolName() { return sRetrProtName; }
        


        //accepts strings that look like "RTSP/1.0" etc...
        static RTSPVersion      GetVersion(StrPtrLen &versionStr);
        static StrPtrLen&       GetVersionString(RTSPVersion version)
            { return sVersionString[version]; }
        
    private:

        //for other lookups
        static StrPtrLen            sMethods[];
        static StrPtrLen            sHeaders[];
        static StrPtrLen            sStatusCodeStrings[];
        static StrPtrLen            sStatusCodeAsStrings[];
        static Int32                sStatusCodes[];
        static StrPtrLen            sVersionString[];
        
        static StrPtrLen            sRetrProtName;

};
#endif // __RTSPPROTOCOL_H__





















